<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ page import="com.msmall.base.util.ConstantDB" language="java"%>
<c:set var="AVALIABLE" value="<%=ConstantDB.AVALIABLE%>"></c:set>
<script type="text/javascript" charset="utf-8"  src="${ctx}/editor/kindeditor-min.js"></script>

<tiles:insertDefinition name="html.bbs.sight.introduce">
	<tiles:putAttribute name="boardId" value="${bid}"></tiles:putAttribute>
</tiles:insertDefinition>

<div class="f_listbutdiv">
	<p class="fl w250">
		<a href="#anchor_reply">
			<input class="but88green" type="button" value="我要回复">
		</a>
		<input class="but88" onclick="javascript:window.open('<c:url value="/bbs/nt.do?bid=${bid}"/>')" type="button" value="我要发帖">
	</p>
	<p class="fr">
		<a href="<c:url value="/bbs/bi.do?bid=${board.boardId}" />">
			<img src="images/fs_06.jpg">
		</a>
	</p>
</div>
<c:if test="${page.pageIndex < 2}">
	<table class="f_showtable" cellspacing="0" cellpadding="0" border="0">
		<tbody>
		<tr valign="top" align="left">
		<td>
			<table class="f_showtable1" width="100%" cellspacing="0" cellpadding="0" border="0">
				<tr valign="middle" align="left">
					<td class="table1bg" width="18%" align="center">
						查看
						<font class="sf00"><c:out value="${topic.clickAmount}"/></font>
						| 回复
						<font class="sf00"><c:out value="${topic.threadAmount}"/></font>
					</td>
					<td class="sH18Bf60" width="67%" style="border-right:none">
						<c:out value="${topic.title}"/>
						
						<ms:set topicId="${tid}" type="elite" value="${topic.elite}" boardId="${bid}"></ms:set>
						<ms:set topicId="${tid}" type="top" value="${topic.top}" boardId="${bid}"></ms:set>
						<ms:set topicId="${tid}" type="commend" value="${topic.commend}" boardId="1"></ms:set>
						<ms:set topicId="${tid}" type="rmc" value="X" boardId="${bid}"></ms:set>
					</td>
					<td class="s666">
					</td>
				</tr>
			</table>
		</td>
		</tr>
		</tbody>
	</table>
	<table class="f_showtable2" cellspacing="0" cellpadding="0" border="0">
		<tr valign="top" align="left">
			<td class="table1bg" width="18%">
				<p class="f_showname">
					<ms:user type="nickname" link="true" userid="${topic.userid}" nickname="${topic.nickname}" style="a2"></ms:user>
				</p>
				<p class="f_showphoto">
					<c:set var="avatarpath"><ms:user type="avatar" link="false" userid="${topic.userid}" nickname="" style=""/></c:set>
					<img style="width:130px;height:110px;" src="${ctx}/${avatarpath}">
				</p>
				<div class="f_showmessage">
					<dl class="f_showmessdl">
						<dt>
							<font class="sBf60">
								<ms:user type="bbstopic" link="false" userid="${topic.userid}" nickname="" style=""/>
							</font>
							<br>
							主题
						</dt>
						<dd>
							<font class="sBf60">
								<ms:user type="bbsthread" link="false" userid="${topic.userid}" nickname="" style=""/>
							</font>
							<br>
							回帖
						</dd>
						<dd>
							<font class="sBf60">
								<ms:user type="bbselite" link="false" userid="${topic.userid}" nickname="" style=""/>
							</font>
							<br>
							精华
						</dd>
					</dl>
					<p class="f_showmessp">
						<img src="images/fs_27.jpg">
						<img src="images/fs_27.jpg">
						<img src="images/fs_27.jpg">
					</p>
					<p class="f_showmessp">
						积分:
						<font class="s705">
							<ms:user type="score" link="false" userid="${topic.userid}" nickname="" style=""/>
						</font>
					</p>
					<p class="f_showmessp">
						<span class="f_addfriend"></span>
						<a class="l666" href="#" onclick="requestFriend(${topic.userid});">加好友</a>
						<span class="f_message"></span>
						<a class="l666" href="#">发消息</a>
					</p>
				</div>
			</td>
			<td width="82%">
				<div class="f_showabout">
					<p class="fl">
						<span class="f_photoico"></span>
							发表于<fmt:formatDate value="${topic.createTime}" pattern="yyyy-MM-dd HH:mm"/>
							&nbsp;&nbsp;&nbsp;
							<a href="javascript:saveFavorite()">加入收藏</a>
							|<a href="javascript:viewTopicOwner()">只看楼主</a>
							|<a href="javascript:saveAbuse()">举报</a>
					</p>
					<p class="fr">
					</p>
				</div>
				<div class="f_showtext">
					<jsp:include page="/${topic.htmlPath}"></jsp:include>
				</div>
			</td>
		</tr>
	</table>
</c:if>
<c:forEach var="thread" items="${page.items}" varStatus="status">
	<table class="f_showtable2" cellspacing="0" cellpadding="0" border="0">
	<tr valign="top" align="left">
		<td class="table1bg" width="18%">
			<p class="f_showname">
				<ms:user type="nickname" link="true" userid="${thread.userid}" nickname="${thread.nickname}" style="a2"></ms:user>
			</p>
			<p class="f_showphoto">
				<c:set var="avatarpath"><ms:user type="avatar" link="false" userid="${thread.userid}" nickname="" style=""/></c:set>
				<img style="width:130px;height:110px;" src="${ctx}/${avatarpath}">
			</p>
			<div class="f_showmessage">
				<dl class="f_showmessdl">
					<dt>
						<font class="sBf60">
							<ms:user type="bbstopic" link="false" userid="${topic.userid}" nickname="" style=""/>
						</font>
						<br>
						主题
					</dt>
					<dd>
						<font class="sBf60">
							<ms:user type="bbsthread" link="false" userid="${topic.userid}" nickname="" style=""/>
						</font>
						<br>
						回帖
					</dd>
					<dd>
						<font class="sBf60">
							<ms:user type="bbselite" link="false" userid="${topic.userid}" nickname="" style=""/>
						</font>
						<br>
						精华
					</dd>
				</dl>
				<p class="f_showmessp">
					<img src="images/fs_27.jpg">
					<img src="images/fs_27.jpg">
					<img src="images/fs_27.jpg">
				</p>
				<p class="f_showmessp">
					积分:
					<font class="s705">
						<ms:user type="score" link="false" userid="${thread.userid}" nickname="" style=""/>
					</font>
				</p>
				<p class="f_showmessp">
					<span class="f_addfriend"></span>
					<a class="l666" href="#" onclick="requestFriend(${thread.userid});">加好友</a>
					<span class="f_message"></span>
					<a class="l666" href="#">发消息</a>
				</p>
			</div>
		</td>
		<td width="82%">
			<div class="f_showabout">
				<p class="fl">
					<span class="f_photoico"></span>
					发表于<fmt:formatDate value="${thread.createTime}" pattern="yyyy-MM-dd HH:mm"/>
					<a href="#">只看该作者</a>
				</p>
				<p class="fr"></p>
			</div>
			<div class="f_showtext">
				<c:choose>
					<c:when test="${thread.enabled == AVALIABLE}">
						<jsp:include page="/${thread.htmlPath}"></jsp:include>
					</c:when>
					<c:otherwise>
						<jsp:include page="thread_notexist.jsp"></jsp:include>
					</c:otherwise>
				</c:choose>
			</div>
			<p class="f_showoperate">
			</p>
		</td>
	</tr>
	</table>
</c:forEach>

<div class="f_listpage martop10">
	<div class="pagediv">
		<jsp:include page="/common/pager2.jsp"></jsp:include>
	</div>
</div>
<div class="f_listsent martop10">
	<div class="f_listsentnav">
		<p class="f_listsentnavbg">我要回复</p>
		<c:if test="${not empty message}">
			<div id="div_thread_error" style="display:block">
				<c:out value="${message}"></c:out>
			</div>
		</c:if>
	</div>
</div>
<div class="f_sentcontdiv">
	<div class="f_showbackmess">
		<form id="f_new_thread" action="<c:url value='/bbs/sd.do' />" method="post">
			<input type="hidden" name="tid" value="${tid}"/>
			<input type="hidden" name="bid" value="${bid}"/>
			<input type="hidden" name="pi" value="${pi}"/>
			<textarea id="thread_content" name="thread.content" class="f_sentcontform1" style="height:150px;">
				<c:out value='${thread.content}'/>
			</textarea>
			<p class="padtop10">
				<span class="marrigh10">
				<input class="but62" type="submit" value="回  复" name="submitThread">
				</span>
			</p>
		</form>
	</div>
</div>

<script type="text/javascript">
KE.show({
	id : 'thread_content',
	imageUploadJson : ctx+'/h/keditor.do',
	fileManagerJson : ctx + '/editor/jsp/file_manager_json.jsp',
	allowFileManager : true,
	afterCreate : function(id) {
		KE.event.ctrl(document, 13, function() {
			KE.util.setData(id);
			document.forms['thread_content'].submit();
		});
		KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
			KE.util.setData(id);
			document.forms['thread_content'].submit();
		});
	}
});
function saveFavorite(){
	var url = ctx + "/bbs/safi.do";
	$.ajax({
		type : "POST",
		url : url,
		data : "tid=" + "<c:out value='${topic.topicId}'/>",
		dataType:"html", 
		timeout:20000,
		success : function(data){
			processEasyResult(data);
		},
		error: function(){
		}
	});
}
function saveAbuse(){
	var url = ctx + "/h/report.do";
	$.ajax({
		type : "POST",
		url : url,
		data : "entityId=<c:out value='${topic.topicId}'/>&abuseType=1",
		dataType:"html", 
		timeout:20000,
		success : function(data){
			processAbuseResult(data);
		},
		error: function(){
		}
	});
	
}
function processAbuseResult(result){
	if(result.toUpperCase().indexOf("FALSE")==0){
		var content = $(result).find('content').text();
		alert(content);
	}else{
		var position = "";
		var value = "";
		$(result).find('item').each(function(){
			position = $(this).find('position').text();
			value = $(this).find('value').text();
		});
		window.location.href = ctx + position;
	}
}
function viewTopicOwner(){
	window.location.href = ctx + "/bbs/vo.do?tid=<c:out value='${topic.topicId}'/>";
}
function processEasyResult(result){
	var content = $(result).find('content').text();
	alert(content);
}
</script>